<template>
  <card-component :content-title="contentTitle"
                  :page="page"
                  @handleSizeChange="handleSizeChange"
                  @handleCurrentChange="handleCurrentChange">

    <table-component slot="table"
                     :table-header="tableHeader"
                     :table-data="tableData"
                     @handleEdit="handleEdit"
                     @handleDelete="handleDelete"></table-component>

  </card-component>

</template>

<script>



  import card from '@/base/card.vue'
  import table from '@/base/AutoWidthTable.vue'
  import request from '@/common/js/request'
  import util from '@/common/js/util'

  export default {
    data() {
      return {
        chanxian:'',
        contentTitle: this.$getTextByLangKey('Bom列表'),
        tableHeader: [],
        tableData: [],
        page: {
          currentPage: 1,
          total: 0,
          pageSize: 20,
        },
      }
    },
    created: function () {

      this.fetchData()
    },

    watch: {
      // 如果路由有变化，会再次执行该方法
      '$route': 'fetchData'
    },

    methods: {
      fetchData: function () {
        this.chanxian = this.$route.query.chanxian
        this.contentTitle = this.chanxian+ this.$getTextByLangKey('Bom列表')

        this.requestBomList()
      },

      destroyed:function () {

        //启动自动刷新的线程，threadOpen = false
        console.log('destroyed')
      },

      requestBomList(){
        request.requestBomList(this.chanxian,res=>{

          var header = [{type: "index", isShow: true}, {prop: 'bomname', label: this.$getTextByLangKey("名称"), isShow: true}]
          var tableData = []
          res.data.data.forEach(function (item) {
            // console.log(item)
            let c = {bomname: item}
            tableData.push(c)
          })

          this.tableHeader = header
          this.tableData = tableData

          this.page.currentPage = res.data.data.pageNum
          this.page.total = res.data.data.total
          this.page.pageSize = res.data.data.pageSize
        })
      },
      handleEdit: function (index, row) {
        this.$emit('handleEdit', index, row)
      },
      handleDelete: function (index, row) {
        this.$emit('handleDelete', index, row)
      },
      rowClick: function (row, event, column) {
      },
      handleSizeChange: function (val) {
        this.$emit("handleSizeChange", val)
      },

      handleCurrentChange: function (val) {
//        console.log('sbsbsbsb')
        this.page.currentPage = val
//        this.fetchData()
      },
    },
    components: {
      'card-component': card,
      'table-component': table,
    },

  }
</script>


<style scoped>
  .el-card {
    box-shadow: 0 0;
    border-radius: 0;
    border:none;
  }
</style>


